package com.website.web.back.controller.website;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.website.common.annotation.Log;
import com.website.common.enums.BusinessType;
import com.website.custom.domain.WHonorCharm;
import com.website.custom.service.IWHonorCharmService;
import com.website.common.core.controller.BaseController;
import com.website.common.core.domain.AjaxResult;
import com.website.common.utils.poi.ExcelUtil;
import com.website.common.core.page.TableDataInfo;

/**
 * 荣誉与风采Controller
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@Controller
@RequestMapping("/back/custom/charm")
public class WHonorCharmController extends BaseController
{
    private String prefix = "back/website/charm";

    @Autowired
    private IWHonorCharmService wHonorCharmService;

    @RequiresPermissions("system:charm:view")
    @GetMapping()
    public String charm()
    {
        return prefix + "/charm";
    }

    /**
     * 查询荣誉与风采列表
     */
    @RequiresPermissions("system:charm:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WHonorCharm wHonorCharm)
    {
        startPage();
        List<WHonorCharm> list = wHonorCharmService.selectWHonorCharmList(wHonorCharm);
        return getDataTable(list);
    }

    /**
     * 导出荣誉与风采列表
     */
    @RequiresPermissions("system:charm:export")
    @Log(title = "荣誉与风采", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WHonorCharm wHonorCharm)
    {
        List<WHonorCharm> list = wHonorCharmService.selectWHonorCharmList(wHonorCharm);
        ExcelUtil<WHonorCharm> util = new ExcelUtil<WHonorCharm>(WHonorCharm.class);
        return util.exportExcel(list, "荣誉与风采数据");
    }

    /**
     * 新增荣誉与风采
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存荣誉与风采
     */
    @RequiresPermissions("system:charm:add")
    @Log(title = "荣誉与风采", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WHonorCharm wHonorCharm)
    {
        return toAjax(wHonorCharmService.insertWHonorCharm(wHonorCharm));
    }

    /**
     * 修改荣誉与风采
     */
    @RequiresPermissions("system:charm:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WHonorCharm wHonorCharm = wHonorCharmService.selectWHonorCharmById(id);
        mmap.put("wHonorCharm", wHonorCharm);
        return prefix + "/edit";
    }

    /**
     * 修改保存荣誉与风采
     */
    @RequiresPermissions("system:charm:edit")
    @Log(title = "荣誉与风采", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WHonorCharm wHonorCharm)
    {
        return toAjax(wHonorCharmService.updateWHonorCharm(wHonorCharm));
    }

    /**
     * 删除荣誉与风采
     */
    @RequiresPermissions("system:charm:remove")
    @Log(title = "荣誉与风采", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wHonorCharmService.deleteWHonorCharmByIds(ids));
    }
}
